﻿using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    public float walkSpeed;
    public float rotaSpeed;

    private Rigidbody rigid;
    private Animation anim;
    void Awake()
    {
        rigid = GetComponent<Rigidbody>();
        anim = GetComponent<Animation>();
    }
	void Update () {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        Quaternion rota = Quaternion.LookRotation(transform.forward * (v + 1.5f) + transform.right * h);
        transform.rotation = Quaternion.Slerp(transform.rotation, rota, rotaSpeed * Time.deltaTime);

        transform.position = Vector3.Lerp(transform.position, transform.forward * walkSpeed * v * Time.deltaTime + transform.position, 50 * Time.deltaTime);

        if(Mathf.Abs(v) > 0.3f)
        {
            anim.CrossFade("Run");
        }
        else
        {
            anim.Stop();
        }

	}
}
